/*
 * RolloverButton.java - Class for buttons that implement rollovers
 */

package org.lex.swing.widgets;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;

/**
 * If you wish to have rollovers on your buttons, use this class.
 * 
 * Unlike the Swing rollover support, this class works outside of
 * <code>JToolBar</code>, and does not require undocumented client property
 * hacks or JDK1.4-specific API calls.
 * <p>
 * 
 * Note: You should not call <code>setBorder()</code> on your buttons, as they
 * probably won't work properly.
 */
public class RolloverButton extends JButton {
	/*
	 * FIXME 1����defualtButton����Ϊtrue��ʱ��Ӧ���ڰ�ť��Χ��ʾһ���߿�
	 * ����������ⲻ֪����ôȥ����
	 * 2��JButton.isDefaultButton()�ƺ���һ���ȽϺ�ʱ�Ĳ������Ƿ�Ӧ��
	 * ����һ��JRootPane�Խ�ʡ�����أ�
	 */

	public RolloverButton() {
		super();
		this.setContentAreaFilled(false);
		this.addMouseListener(new MouseOverHandler());
	}

	public void updateUI() {
		super.updateUI();
		setBorderPainted(this.isDefaultButton());
	}

	// ����͸����
	public boolean isOpaque() {
		return false;
	}

	/**
	 * Make the border visible/invisible on rollovers
	 */
	class MouseOverHandler extends MouseAdapter {
		public void mouseEntered(MouseEvent e) {
			if (isEnabled()) {
				setBorderPainted(true);
				setContentAreaFilled(true);
			}
		}

		public void mouseExited(MouseEvent e) {
			setBorderPainted(isDefaultButton());
			setContentAreaFilled(false);
		}
	}
}
